/*
   Project:    SMS_Controller
   Company:    
   Author:     Dima
   Start date: 01.12.2006 
*/

/* $Log: main.c,v $
/* Revision 1.15  2009/11/30 15:33:58  dimitrip
/* Added new command - SM ( Send SMS message )
/*
/* Revision 1.14  2009/11/03 10:54:36  dimitrip
/* Add "Car. Petrol Blocking" application
/*
/* Revision 1.13  2009/10/29 10:25:42  dimitrip
/* Add Print_SMS application
/*
/* Revision 1.12  2007/11/04 17:51:39  dimitrip
/* *** empty log message ***
/*
/* Revision 1.11  2007/11/04 14:38:20  dimitrip
/* Input 2 as PANIC button
/*
/* Revision 1.10  2007/09/09 10:57:15  dimitrip
/* Add RF Remote, ARM mode;
/*
/* Revision 1.9  2007/08/26 16:06:41  dimitrip
/* RF - OK;
/*
/* Revision 1.8  2007/08/26 05:26:59  Administrator
/* Add RF modules need integration;
/*
/* Revision 1.7  2007/02/05 12:30:50  dimitrip
/* *** empty log message ***
/*
/* Revision 1.7  2007/01/08 16:26:43  dimitrip
/* *** empty log message ***
/*
/* Revision 1.6  2006/12/21 16:13:28  dimitrip
/* *** empty log message ***
/*
/* Revision 1.5  2006/12/17 17:00:09  dimitrip
/* *** empty log message ***
/*
/* Revision 1.4  2006/12/14 15:58:24  dimitrip
/* *** empty log message ***
/*
/* Revision 1.3  2006/12/11 16:37:18  dimitrip
/* Library of teh Customers Service;
/*
/* Revision 1.2  2006/12/07 16:24:48  dimitrip
/* *** empty log message ***
/* */
#include "main.h"
#include "Print_SMS.h"
#include "Car_PetrolBlocking.h"
#include "Translator.h" 

		__CONFIG(1, FCMDIS & HSPLL);
      __CONFIG(2, PWRTEN & BOREN & BORV21 & WDTEN & WDTPS8K);/* WDT PERIOD == 32.768 sec */
		__CONFIG(3, MCLREN );
//__CONFIG(4, BBSIZ4K & LVPDIS & DEBUGDIS & XINSTDIS & STVRDIS );
      __CONFIG(4, LVPDIS & DEBUGDIS & XINSTDIS & STVRDIS );
//  __CONFIG(4, LVPDIS & DEBUGDIS & XINSTDIS & STVRDIS );
	//	__CONFIG(4,  LVPDIS & DEBUGEN & XINSTDIS & STVRDIS );
//Dima	__CONFIG(5, CPALL );
//  __CONFIG(5, UNPROTECT );
	//	__CONFIG(6, WPC );
	//	__CONFIG(6, WRTEN );


void main ( void )
{
	InitDevice();
	delay_ms(50);
	InitModules();
	
#if defined(APP_CAR_PETROL_BLOCKING)
	Debug("\r\n ========== APP_CAR_PETROL_BLOCKING ===========\r\n");
#endif
	
	Debug("\n\r Modem Registration");
	
	dbg("============ RESET ==========="); //Dima
	for(;;)							  /* Main Loop*/
	{
		CLRWDT();
		SysTime();


		Drive_Receivers();

		//DataMode_Service();

		if ( Execute_Module_1 != NULL )
		{
			(*Execute_Module_1)();	  
		}

		if ( Tools != NULL )
		{
			Tools();	  
		}

		if ( Special != NULL )
		{
			Special();
		}
			
		AuxPortMonitor();


		Drive_Inputs();
		
		CellNetwork_RSSI();

		CellNetwork_Reg_Monitor();	/* check registration into cell network; see CellNetwork_Event */
#if defined(NEIGHBOR_CELLS_APP)	
			if ( !Neighbor_Cells_Monitor() )
			{
				LED = 0;
			}

#elif defined(APP_PRINT_SMS)
			LED = 0;
			Print_SMS();

#elif defined(APP_CAR_PETROL_BLOCKING)			
			CarPetrolBlocking();
			IncomingCallMonitor();
			CarAlarm();
			//Car_RF();
			Drive_RF_Input();

#elif defined(APP_COMMAND_TRANSLATOR)
			CommandTranslator();
			IncomingCallMonitor();
#else
			IncomingCallMonitor();
			InputsManager();
			Drive_RF_Input();
			RF_Manager();
			LED = 0;
#endif

/* 		if ( RegistrationStatus.REGISTERED == TRUE ) */
/* 		{ */
				
/* 		} */
/* 		else */
/* 			if ( Time_500ms )  */
/* 			{ */
/* #if !defined(APP_PRINT_SMS) */
/* 				putsf(".", AUX_PORT); */
/* #endif */
/* 				LED ^= 1; */
/* 			} */
	
			
			
		MainStateMachine();
			
		Drive_Outputs();
		//Registration();
//		}
	} /* Main Loop*/
	
}






